< previous page page_559 next page >

Page 559
Examples Filename: ApiFind.frm
In the example shown in Figure 28.2, you can search for a state code in a list box full of state codes. Click the Search button to invoke the Click event. Heres the code:
9f31265bb40b592b1929e18a47ab28e5.gif
Private Sub cmdSearch_Click()
   Dim strSearch As String
   Dim lngPos As Long

   strSearch = InputBox$("Enter String To Find:", "Search")

   With lstStates
      If strSearch = "" Then
         .ListIndex = 0
      Else
         lngPos = SendMessage(.hwnd, _
                             LB_FINDSTRING, _
                             -1, _
                             ByVal strSearch)
         If lngPos >= 0 Then
            .ListIndex = lngPos
         End If
      End If
   End With
End Sub
8160-0559a.gif
Figure 28.2
Finding a string in a list box using 
SendMessage().
The SendMessage() API always expects a handle to a window as the first parameter. A handle is a long integer that uniquely identifies a window within the Windows environment. Almost every control you use with Visual Basic is a window, and these controls have an hWnd (handle to a window) property you can use for this parameter. The next parameter is the specific message you want to send to the control. In this case, its a constant value that youll also retrieve from the API Text Viewer.

 
< previous page page_559 next page >

If you like this book, buy it!